import React, { useRef } from 'react'
import { PageHeaderWrapper } from '@ant-design/pro-layout'
import ProTable from '@ant-design/pro-table'
import { connect} from 'umi'
import { queryContractList } from '../service'
import {contractTypeStatusList,laborContractYearsList,signRemarkList,endTypeList} from "@/utils/constant";
import moment from 'moment'

const TableList = () => {
  const actionRef = useRef();

  const columns = [
    {
      title: '序号',
      render:(text,record,index)=>`${index+1}`,
      hideInSearch: true,
    },
    {
      title: '签署原因',
      dataIndex: 'operateType',
      hideInSearch: true,
      render: (text) => {
        const res = signRemarkList.find((item) => item.value === parseInt(text));
        return res ? res.label : text
      },
    },
    {
      title: '签订合同时所在公司',
      dataIndex: 'beginOrgName'
    },
    {
      title: '签订合同时所在部门',
      dataIndex: 'beginJobName'
    },
    {
      title: '签订合同时岗位',
      dataIndex: 'beginJobName'
    },
    {
      title: '合同类型',
      dataIndex: 'beginContractType',
      valueEnum: {
        1: { text: contractTypeStatusList[0].label },
        2: { text: contractTypeStatusList[1].label },
        3: { text: contractTypeStatusList[2].label },
      },
    },
    {
      title: '合同生效日',
      dataIndex: 'contractBeginDate',
      hideInSearch: true,
      render: (text) => {
        return text !== '-'  ? moment(text).format('YYYY-MM-DD') : ''
      },
    },
    {
      title: '合同预计终止日期',
      dataIndex: 'contractEndDate',
      hideInSearch: true,
      render: (text) => {
        return text !== '-'  ? moment(text).format('YYYY-MM-DD') : ''
      },
    },
    {
      title: '甲方主体',
      dataIndex: 'employerCompany',
      hideInSearch: true,
    },
    {
      title: '合同期限类型',
      dataIndex: 'contractTimeType',
      valueEnum: {
        0: { text: laborContractYearsList[0].label },
        1: { text: laborContractYearsList[1].label },
        2: { text: laborContractYearsList[2].label },
        3: { text: laborContractYearsList[3].label },
      },
    },
    {
      title: '当前应用合同',
      dataIndex: 'status',
      valueEnum: {
        0: { text: '未生效', status: 'Default' },
        1: { text: '已生效', status: 'Success' },
        2: { text: '合同过期', status: 'Default' },
      },
    },
    {
      title: '合同实际终止日期',
      dataIndex: 'endTime',
      hideInSearch: true,
      render: (text) => {
        return text !== '-' ? moment(text).format('YYYY-MM-DD') : ''
      },
    },
    {
      title: '解除合同签订日期',
      dataIndex: 'endSignDate',
      hideInSearch: true,
      render: (text) => {
        return text !== '-' ? moment(text).format('YYYY-MM-DD') : ''
      },
    },
    {
      title: '解除合同签订地址',
      dataIndex: 'endContractUrl',
      hideInSearch: true,
      onCell: ()=>{
        return {
          style:{
            maxWidth:200,
            overflow:'hidden',
            whiteSpace:'nowrap',
            textOverflow:'ellipsis',
            cursor:'pointer',
          }
        }
      },
      render: (text,record) =>{
        return <a href={record.endContractUrl} target="_blank">{text}</a>
      }
    },
    {
      title: '解除类型',
      dataIndex: 'endType',
      hideInSearch: true,
      render: (text) => {
        const res = endTypeList.find((item) => item.value === parseInt(text));
        return res ? res.label : text
      },
    },
    {
      title: '查看合同',
      dataIndex: 'beginContractUrl',
      hideInSearch: true,
      onCell: ()=>{
        return {
          style:{
            maxWidth:200,
            overflow:'hidden',
            whiteSpace:'nowrap',
            textOverflow:'ellipsis',
            cursor:'pointer',
          }
        }
      },
      render: (text,record) =>{
        return <a href={record.beginContractUrl} target="_blank">{text}</a>
      }
    }
  ];

  return (
    <PageHeaderWrapper>
      <ProTable
        search={false}
        actionRef={actionRef}
        rowKey="id"
        request={(params) => queryContractList(params)}
        columns={columns}
        scroll={{ x: '180%' }}
      />
    </PageHeaderWrapper>
  )
}

export default connect(() => ({
}))(TableList)
